package datamining.parsers;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.text.ParseException;
import java.util.Collection;

import datamining.graph.Graph;
import datamining.graph.GraphFactory;


/** 
 * 创建于 2012-11-14 下午11:00:15
 * 
 * @author xujinghu (jinghuxu@nudt.edu.cn)
 * 
 * 版权所有 2012 xujinghu
 * 
 * 许可证 Apache
 */
public interface GraphParser<NodeType, EdgeType> extends Serializable {

	/** @return the edge parser used */
	public LabelParser<EdgeType> getEdgeParser();

	/** @return the node parser used */
	public LabelParser<NodeType> getNodeParser();

	/**
	 * parses multiple graphs for the given input stream and creates a
	 * collection of the corresponding graphs
	 * 
	 * @param io
	 * @param factory
	 *            a factory that creates a corresponding empty graph
	 * @return a collection of the represented graphs
	 * @throws ParseException
	 * @throws IOException
	 */
	public Collection<Graph<NodeType, EdgeType>> parse(InputStream io,
			GraphFactory<NodeType, EdgeType> factory) throws ParseException,
			IOException;

	/**
	 * parses one sequence from the given input string and creates the sequence that
	 * is represented by it
	 * 
	 * @param input
	 * @param factory
	 *            a factory that creates a corresponding empty graph
	 * @return the corrsponding graph
	 * @throws ParseException
	 *             if the input string cannot be parsed correctly
	 */
	public Graph<NodeType, EdgeType> parse(String input,
			GraphFactory<NodeType, EdgeType> factory) throws ParseException;

	/**
	 * @param graph
	 * @return a serialized representation of the given graph
	 */
	public String serialize(Graph<NodeType, EdgeType> graph);

	/**
	 * writes all serialized representations of the given graphs to the output
	 * stream
	 * 
	 * @param out
	 * @param graphs
	 * @throws IOException
	 */
	public void serialize(OutputStream out,
			Collection<Graph<NodeType, EdgeType>> graphs) throws IOException;

}

